package Demo09;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

/*
表格
 */
public class TableDemo  extends JFrame {
    private  JPanel mainPanel;
    private  JScrollPane scrollPane;//滚动面板
    private  JTable table;
    private DefaultTableModel model;//操作表格数据

    //构造方法
    public  TableDemo(){
        mainPanel=new JPanel(new BorderLayout());//边界布局
//        model=new DefaultTableModel()
        //表头
        String[] heads={"学号","姓名","性别","团员否","籍贯","出生日期","家庭住址","联系方式","入学日期"};

        model=new DefaultTableModel(heads,0);

        table=new JTable(model);

        scrollPane=new JScrollPane(table);


        setContentPane(mainPanel);
        mainPanel.add(scrollPane,"Center");


        setBounds(100,100,500,400);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        fillData();

    }

    private void fillData() {
//        model.addRow();
        for (int i = 1; i < 50; i++) {
            //String[] heads={"学号","姓名","性别","团员否","籍贯","出生日期","家庭住址","联系方式","入学日期"};

            model.addRow(new  String[]{"0"+i,"小向"+i,"男","团员","四川广元","2000-11-11","四川广元","1341919191","2019-09-01"});

//            model.removeRow(10);//只能一行行的删除；【删除第0 行】
        }
    }

    public static void main(String[] args) {
        new  TableDemo();
    }
}

//applet----------java小程序；
